﻿//// Copyright CraftingCode.Org 2013
namespace CraftingCode.SymbolicCalculator.UnitTests
{
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class EvaluationTests
    {
        [TestMethod]
        public void EvaluateAdditionOfLiterals()
        {
            TestExpressionEvaluation(6, "1+2+3");            
        }

        [TestMethod, ExpectedException(typeof(UnknownTokenException)), Timeout(100)]
        public void EvaluateUnknownToken()
        {
            TestExpressionEvaluation(7, "#");
        }
   
        //[TestMethod]
        //public void EvaluateSubtractinOfTwoLiterals()
        //{
        //    TestExpressionEvaluation(7, "9-2");
        //}
       
        [TestMethod]
        public void EvaluateLiteralNumberOne()
        {
            TestLiteralEvaluation(1);
        }
        
        [TestMethod]
        public void EvaluateLiteralNumberTwo()
        {
            TestLiteralEvaluation(2);
        }
        
        private static void TestLiteralEvaluation(int literal)
        {            
            TestExpressionEvaluation(literal, literal.ToString());
        }

        private static void TestExpressionEvaluation(int expectedValue, string expression)
        {
            var node = Parser.Parse(expression);
            Assert.AreEqual(expectedValue, node.Evaluate());
        }
   }    
}